package com.gxa.uhome.service.impl;

import com.gxa.uhome.exception.BusinessException;
import com.gxa.uhome.mapper.UserAddressMapper;
import com.gxa.uhome.pojo.UserAddress;
import com.gxa.uhome.service.UserAddressService;
import com.gxa.uhome.service.UserService;
import com.gxa.uhome.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * User: Sanruy Mu
 * Date: 2021/06/09 9:50
 * Description:
 * Version: V1.0
 */
@Service("userAddressServiceImpl")
public class UserAddressServiceImpl implements UserAddressService {
    @Autowired
    UserAddressMapper userAddressMapper;
    @Override
    public List<UserAddress> selectByUserId(Integer id) throws BusinessException {
        List<UserAddress> userAddresses = userAddressMapper.selectByUserId(id);
        if(userAddresses!=null){
            return userAddresses;
        }else{
         throw new BusinessException("查看失败，稍后再试");
        }
    }

    @Override
    public Integer addAddress(UserAddress userAddress) throws BusinessException {
        Integer insert = userAddressMapper.insert(userAddress);
        if(insert!=null){
            return insert;
        }else{
            throw new BusinessException("添加失败");
        }
    }

    @Override
    public Integer edit(UserAddress userAddress) throws BusinessException {
        Integer update = userAddressMapper.update(userAddress);
        if(update != null){
            return update;
        }else{
            throw new BusinessException("修改失败");
        }
    }

    @Override
    public Integer deleteAddress(Integer id) throws BusinessException {
        Integer delete = userAddressMapper.delete(id);
        if(delete!=null){
            return delete;
        }else{
            throw new BusinessException("删除失败");
        }
    }
}